package com.micro.service.common.po;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel("返回信息通用实体类")
public class CommonResult<T> implements Serializable {
    @ApiModelProperty(value = "状态编码,成功默认为200")
    private String resultCode;
    @ApiModelProperty(value = "返回信息")
    private String resultMessage;
    @ApiModelProperty(value = "是否成功,true:成功,false:失败")
    private Boolean success;
    @ApiModelProperty(value = "返回数据")
    private T data;

    public static <T> CommonResult success(T data) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(true);
        commonResult.setData(data);
        commonResult.setResultMessage("success");
        commonResult.setResultCode("200");
        return commonResult;
    }

    public static <T> CommonResult success(T data, String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(true);
        commonResult.setData(data);
        commonResult.setResultMessage(message);
        commonResult.setResultCode("200");
        return commonResult;
    }

    public static CommonResult fail(String resultCode, String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(false);
        commonResult.setResultMessage(message);
        commonResult.setResultCode(resultCode);
        return commonResult;
    }

    public static CommonResult fail(String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setSuccess(false);
        commonResult.setResultMessage(message);
        return commonResult;
    }


}
